#include "EpollServer.hpp"

Reponse calculator(const Request &request)
{
    Reponse rep(0, 0);
    switch (request._op)
    {
        case '+':
            rep._result = request._x + request._y;
            break;
        case '-':
            rep._result = request._x - request._y;
            break;
        case '*':
            rep._result = request._x * request._y;
            break;
        case '/':
            if(request._y == 0)
            {
                rep._exit_code = -1;
            }
            else
            {
                rep._result = request._x / request._y;
            }
            break;
        case '%':
            if(request._y == 0)
            {
                rep._exit_code = -1;
            }
            else
            {
                rep._result = request._x % request._y;
            }
            break;
    }
    return rep;
}

void Usage(const std::string proc)
{
    std::cout << "\n\t" << proc << " serverPort" << std::endl;
}

int main(int argc,char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(USER_ERR);
    }

    uint16_t serverPort = atoi(argv[1]);
    EpollServer* server = new EpollServer(serverPort,calculator);
    server->Init();
    server->Dispatcher();
    delete server;
    return 0;
}

